<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>选品库</title>

    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>
</head>
<body style="background-color:#F0F0F0">
<div id="app" style="padding-top:60px" v-cloak>
  <div id="blank" class="header" v-cloak>
    <div v-back.tapmode class="back"></div>
      <span class="title" style="padding-left:46px;">收藏夹</span>
      <img onclick="openMessage()" class="user-header-icon" style="float:right"
           src="../../image/big/user_icon_search_msg.png" tapmode>
      <!-- <img onclick="openSearch()" class="user-header-icon" style="float:right"
          src="../../image/search.png" tapmode> -->
      <span style="position:absolute;font-size:12px;right:25px;top:20px;color:white;background:red;line-height:normal;padding:0 5px;border-radius:7px;z-index: 10"
        v-if="unReadMsgCount>0">{{unReadMsgCount}}
  </div>
  <div class="library_tab" style="position:fixed;top:60px;background:#ffffff;z-index:1000;border-bottom:1px solid #e6e6e6">
      <div class="tab-one" v-myclick="[1, changeBottom]">
          <span :class="{'active':isActive==1}">正在处理({{state.state1count}})</span>
      </div>
      <div class="tab-one" v-myclick="[2, changeBottom]">
          <span :class="{'active':isActive==2}">处理成功({{state.state2count}})</span>
      </div>
      <div class="tab-one" v-myclick="[3, changeBottom]">
          <span :class="{'active':isActive==3}">处理失败({{state.state3count}})</span>
      </div>
  </div>
  <div style="margin-bottom:30px;margin-top:40px;">
  <div class="goods_info" v-for="(good, index) in goods" :key="key">
    <div class="goods-detail" v-myclick="[good, opebrowser]">
      <div class="goods-pic">
        <img v-image-resize="{src:'http:'+good.pic}" :key="good.goods_id">
      </div>
      <div class="goods-detail-right">
        <div class="goods-detail-title">{{good.title}}</div>
        <div class="sell-price">
          <span style="color:#666666">售价：</span><span style="color:#9d0152">￥{{good.price}}</span>
        </div>
        <div class="goods_number">
          <span style="color:#E5001E"><span style="font-size:16px">赚</span> ：{{(good.price*good.profit*gain_rate.t5_gain_rate_max/100).toFixed(2)}}</span>
          <span style="padding-left:10px">销量：{{good.sale_count}}</span>
        </div>
      </div>
    </div>
  </div>
  <lazy-load  v-if="goods.length > 0" style="margin-top:30px"
             count-per-page="20"
             :arr="goods"
             :url="url"
             :param="param"
             ret-attr="goods"
             >
  </lazy-load>
  </div>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/url.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/components.js"></script>
<script>
var vm,
gain_rate,
isActive=1,
    state,
    param,
    goods;
apiready = function () {
  showProgress();
  UIScrollPicture = api.require('UIScrollPicture');
  MNActionButton = api.require('PIActionButton');
  wx = api.require('wx');
  setBSImg();
  var data = {
      member_id: getPrefs('member_id'),
      state:1
  };
  var callback = function (ret) {
      home = ret.content;
      goods = home.goods;
      gain_rate = home.gain_rate;
      state = home.state;
      param={
        state:1,
      }
      initApp();
      api.parseTapmode();
      addListeners();
  };
  pinet.post(URL.getLibraryGoods, data, callback);
  addListeners();
};

function refresh() {
  var data = {
    member_id: getPrefs('member_id'),
    state:1
  };
  var callback = function (ret) {
      var home = ret.content;
      if (vm) {
          vm.goods = home.goods;
          vm.gain_rate = home.gain_rate;
          vm.state = home.state;
          vm.key++;
      } else {
          initApp();
      }
      api.refreshHeaderLoadDone();
  };
  var errback = function () {
      api.refreshHeaderLoadDone();
  };

  pinet.post(URL.getLibraryGoods, data, callback, errback);
}

function initApp() {
    vm = new Vue({
        el: "#app",
        data: {
            state:state,
            param: param,
            goods: goods,
            gain_rate:gain_rate,
            url: URL.getLibraryGoods,
            unReadMsgCount: 0,
            key:0
        },
        methods: {
            changeBottom: function (index) {
              showProgress();
              this.isActive = index;
              var data = {
                  member_id: getPrefs('member_id'),
                  state: index
              };
              var callback = function (ret) {
                var home = ret.content;
                vm.goods = home.goods;
                vm.gain_rate = home.gain_rate;
                vm.state = home.state;
                vm.key++;
                vm.param={
                  state:index,
                };
              };
              pinet.post(URL.getLibraryGoods, data, callback);
            },
            search:function(){
              api.sendEvent({
                  name: 'addlibrary'
              });
              openWin('search');
            },
            opebrowser:function(good){
                if(good.goods_id){
                  openWin('../home/browser', {goods_id: good.goods_id});
                }else if(good.goods_url){
                  openWin('shopbrowser',{auctionurl:good.goods_url,good:good})
                }
            },
        },
    });
}
function addListeners() {
    api.addEventListener({
        name: 'keyback'
    }, function (ret, err) {
        onPageEnd();
        api.sendEvent({
            name: 'addlibrary'
        });
        api.closeWin();
    });

    api.addEventListener({
        name: 'addgoods'
    }, function () {
       refresh();
    });

    api.addEventListener({
        name: 'viewappear'
    }, function () {
        onPageStart();
    });

    api.addEventListener({
        name: 'viewdisappear'
    }, function (ret, err) {
        onPageEnd();
    });

    api.addEventListener({
        name: 'getUnReadMsgCount'
    }, function () {
        vm.unReadMsgCount = ret.value.count;
        api.setAppIconBadge({
            badge: ret.value.count
        });
    });

}

function openMessage() {
    if(!getPrefs('token')){
        reLogin();
    }
    openWin('../user/message');
}

function openSearch() {
    openWin('../mall/search');
}
</script>
</html>
